package com.hfut.eeg.common.component;

import com.hfut.eeg.dto.EerWaves;
import com.hfut.eeg.service.BrainEnergyService;
import com.hfut.eeg.service.BrainFFTService;
import com.hfut.eeg.service.BraninChannelService;
import com.hfut.eeg.service.EerWavesService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component("receiveThread")
@Scope("prototype")
public class ReceiveThread implements Runnable{
    @Autowired
    private BrainFFTService brainFFTService;
    @Autowired
    private BraninChannelService braninChannelService;
    @Autowired
    private BrainEnergyService brainEnergyService;
    @Autowired
    private EerWavesService eerWavesService;

    private static final Logger LOGGER = LoggerFactory.getLogger(ReceiveThread.class);

    private String eegId;
    private ArrayList<ArrayList>Ffts = new ArrayList<>();
    private ArrayList<EerWaves>ErrWaves = new ArrayList<>();
    private ArrayList<ArrayList>BrainChannel = new ArrayList<>();
    private ArrayList<ArrayList>Energy = new ArrayList<>();

    public void setEegId(String eegId) {
        this.eegId = eegId;
    }

    public void setFfts(ArrayList<ArrayList> ffts) {
        Ffts = ffts;
    }

    public void setErrWaves(ArrayList<EerWaves> errWaves) {
        ErrWaves = errWaves;
    }

    public void setBrainChannel(ArrayList<ArrayList> brainChannel) {
        BrainChannel = brainChannel;
    }

    public void setEnergy(ArrayList<ArrayList> energy) {
        Energy = energy;
    }


    @Override
    public void run() {
        int i = brainFFTService.insertFFTByArray(Ffts,eegId);
        if(i<=0)
            LOGGER.warn("fft插入数据库错误");
        else
            LOGGER.info("fft插入成功");

        i = eerWavesService.insertEerWaves(ErrWaves);
        if(i<=0)
            LOGGER.warn("ErrWaves插入数据库错误");
        else
            LOGGER.info("ErrWaves插入成功");

        i = braninChannelService.insertBrainChannelByArr(BrainChannel,eegId);
        if(i<=0)
            LOGGER.warn("BrainChannel插入数据库错误");
        else
            LOGGER.info("BrainChannel插入成功");
        i = brainEnergyService.insertBrainEnergyByArr(Energy,eegId);
        if(i<=0)
            LOGGER.warn("BrainChannel插入数据库错误");
        else
            LOGGER.info("BrainChannel插入成功");



    }
}
